import 'package:get/get.dart';
import 'privacy_state.dart';

class PrivacyLogic extends GetxController {
  final PrivacyState state = PrivacyState();

  // 设置隐私类型
  void setPrivacyType(PrivacyType type) {
    state.privacyType.value = type;
  }
  
  // 切换成员选择状态
  void toggleMemberSelection(Member member) {
    final index = state.members.indexWhere((m) => m.id == member.id);
    if (index != -1) {
      state.members[index].isSelected = !state.members[index].isSelected;
      state.members.refresh();
    }
  }
  
  // 确认选择
  void confirmSelection() {
    // 根据当前选择的隐私类型和选中的成员，构建结果
    Map<String, dynamic> result = {
      'privacyType': state.privacyType.value,
    };
    
    // 如果是选择部分成员可见，则添加选中的成员列表
    if (state.privacyType.value == PrivacyType.selectedMembers) {
      result['selectedMembers'] = state.selectedMembers;
    }
    
    // 返回结果并关闭页面
    Get.back(result: result);
  }
} 